#TODO 导包
import allure
import pytest
from faker import Faker
import conftest
from PO.base.get_driver import GetDriver
from PO.page.page_user_home import PageUserhome
from conftest import login_url, BASE_DIR
from utils.decorator import decorator
from utils.logger import Log

# TODO 测试类使用-------满足条件跳过
version=conftest.version
#TODO 新建测试类
@allure.feature('个人中心模块')
@pytest.mark.skipif(version=='测试',reason="正在调试其他脚本，此用例暂不执行")
class TestEditInfo():
    #TODO 初始化
    def setup_class(self):
        #初始化日志模块
        self.log = Log("编辑用户信息用例").get_logger()
        # TODO 创建一个Faker对象
        self.fake=Faker(locale='zh_CN')
        #TODO 获取driver
        self.driver=GetDriver().get_driver(login_url)
        #TODO 获取个人中心页面对象
        self.userhome=PageUserhome(self.driver)

        with allure.step("前置条件：登录测试账号18325530002"):
            login_data=('18325530002','wsf123456','8888')
            self.userhome.base_qt_login(*login_data)
            self.log.info("登录用户：{}".format(login_data))
            #TODO allure截图
            self.userhome.base_get_allure_image()


    #TODO 结束方法
    def teardown_class(self):
        self.driver=GetDriver().quit_driver()


    @decorator
    @allure.story('编辑个人信息')
    def test_EditInfo(self):
        with allure.step("测试步骤一：点击个人信息"):
            self.userhome.page_click_into_user_info()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤二：编辑头像"):
            self.userhome.page_click_edit_head_pic()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤三：进入iframe1框架"):
            self.userhome.page_to_iframe()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤四：上传图片"):
            filepath = BASE_DIR + r"/image/1.jpg"
            self.userhome.page_upload_image(filepath)
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤五：等待上传成功"):
            self.userhome.page_wait_upload_success()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤六：点击确定使用"):
            self.userhome.page_click_confirm_use()
            self.userhome.base_get_allure_image()
            #TODO 退出iframe框架
            self.driver.switch_to.default_content()

        with allure.step("测试步骤七：编辑昵称"):
            nickname = self.fake.name()
            self.userhome.page_input_edit_nickname(nickname)
            self.userhome.base_get_allure_image()


        with allure.step("测试步骤八：随即选择性别"):
            self.userhome.page_input_edit_sex()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤九：编辑生日"):
            birthday = self.fake.date(pattern="%Y-%m-%d", end_datetime=None)
            self.userhome.page_input_edit_birthday(birthday)
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤十：点击确认保存并截图"):
            self.userhome.page_click_save_btn()
            self.userhome.base_get_allure_image()

        #记录日志
        self.log.info("昵称：{}，生日：{}".format(nickname,birthday))